package com.developer.platform.controller.login;

import com.developer.platform.domain.service.IAuthenticationSource;
import com.veeker.log.annotations.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2020-10-20
 */
@Api(tags = "登出管理")
@Validated
@RestController
public class LogoutController {

    private final IAuthenticationSource authenticationSource;

    public LogoutController(IAuthenticationSource authenticationSource) {
        this.authenticationSource = authenticationSource;
    }

    @ApiOperation(value = "退出登录，清空token")
    @Log(businessType = "注销登录",discription = "退出登录，清空token")
    @PostMapping(value = "/remove", headers = HttpHeaders.AUTHORIZATION)
    public ResponseEntity<?> logout(
            @RequestHeader(value = HttpHeaders.AUTHORIZATION) String authorization) {
        authenticationSource.removeToken(authorization);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

}
